# coding=utf-8
import requests, os, subprocess, requests, time
from lxml import etree

os.environ["NODE_PATH"] = "./node_modules"

page = 6
ts = int(time.time() * 1000)
sn = subprocess.getoutput(f'node jiudian.js {page} {ts}')
print(sn)
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.41",
}
url = "https://www.mafengwo.cn/hotel/info/comment_list"
params = {
    "poi_id": "40061",
    "type": "0",
    "keyword_id": "0",
    "page": page,
    "_ts": ts,
    "_sn": sn
}
response = requests.get(url, headers=headers, params=params).json()["html"]

tree = etree.HTML(response)
div_list = tree.xpath('//div[@class="comm-item _j_comment_item"]')
for div in div_list:
    detail = ''.join(div.xpath('div[@class="txt"]/text()')).replace('\U0001f31f', '')
    create_time = div.xpath("div[@class='comm-meta']/span[@class='time']/text()")
    print(detail, create_time)
